Skip to content

Commit 9476664

Browse files
committed
Fix bug where table could mismatch header vs data when allow_transforms was set false (not easily possible w/current tools)
1 parent 2bc6acf commit 9476664

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/woff2_enc.cc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,20 +272,22 @@ bool ConvertTTFToWOFF2(const uint8_t *data, size_t length,
272272
std::vector<uint8_t> compression_buf(compression_buffer_size);
273273
uint32_t total_compressed_length = compression_buffer_size;
274274

275-
// Collect all transformed data into one place.
275+
// Collect all transformed data into one place in output order.
276276
std::vector<uint8_t> transform_buf(total_transform_length);
277277
size_t transform_offset = 0;
278278
for (const auto& font : font_collection.fonts) {
279-
for (const auto& i : font.tables) {
280-
const Font::Table* table = font.FindTable(i.second.tag ^ 0x80808080);
281-
if (i.second.IsReused()) continue;
282-
if (i.second.tag & 0x80808080) continue;
279+
for (const auto tag : font.OutputOrderedTags()) {
280+
const Font::Table& original = font.tables.at(tag);
281+
if (original.IsReused()) continue;
282+
if (tag & 0x80808080) continue;
283+
const Font::Table* table_to_store = font.FindTable(tag ^ 0x80808080);
284+
if (table_to_store == NULL) table_to_store = &original;
283285

284-
if (table == NULL) table = &i.second;
285-
StoreBytes(table->data, table->length,
286+
StoreBytes(table_to_store->data, table_to_store->length,
286287
&transform_offset, &transform_buf[0]);
287288
}
288289
}
290+
289291
// Compress all transformed data in one stream.
290292
if (!Woff2Compress(transform_buf.data(), total_transform_length,
291293
&compression_buf[0],

0 commit comments

Comments
 (0)